package dli_and_obs.utils

import java.io.{ByteArrayInputStream, File}
import java.util.Properties

import com.obs.services.ObsClient

/**
  * @Description TODO 
  * @Author liutaowei
  * @Date 2019-5-21 10:39
  */
object obs_utils {

  def get_obs_client(properties:Properties) = {
    val endPoint = properties.getProperty("endPoint")
    val ak = properties.getProperty("ak")
    val sk = properties.getProperty("sk")

    // 创建ObsClient实例
    val obsClient = new ObsClient(ak, sk, endPoint)

    obsClient
  }

  /**
    *@Author: Liutaowei
    *@Date:2019-5-20 10:11
    *@Description: jar包上传obs
    */
  def file_load_obs(path:File,obsClient:ObsClient, properties:Properties)={
    println("开始上传jar包至obs")

    val object_path =properties.getProperty("object_path")
    val bucketname =properties.getProperty("bucketname")

    val obs_path = object_path.replace("\\","/").replaceAll("[/]$","") + "/" + path.getName

    if("" == path) println("传入路径存在问题,请仔细检查")
    else {
      try{
        obsClient.putObject(bucketname,obs_path,path)
      }catch {
        case e:Exception =>
          println("state1: 文件上传失败  \n错误原因:"+e.getMessage)
          obsClient.close()
      }
    }

  }




}
